package com.gitee.wsl.mathematics.geometry.d2.curve.equation

import com.gitee.wsl.text.format.format
import kotlin.math.pow

/** This constructor will take the equation constants.
 *
 * Ex: lets assume the function is a function in x,
 * then the equation will be as following: a (X ^ 2) + b X + c.
 *
 * @param a the quadratic term constant
 * @param b the linear term constant
 * @param c the equation constant
 */
class QuadraticEquation(var a: Double, var b: Double, var c: Double) : IEquation {
    // a (X ^ 2) + b X + c

    /** This function will calculate the function at the passed point.
     *
     * @param x the function variable value.
     * @return it will return the calculated function value at the given point
     */
    override fun calculateAtPoint(x: Double): Double {
        return a * x.pow(2.0) + b * x + c
    }


    override fun toString(): String {
        return String.format("%f", a) + " (X ^ 2) " + (if (b > 0) " + " else " - ") +
                String.format("%f", b).substring(1) + " X " + (if (c > 0) " + " else " - ") +
                String.format("%f", c).substring(1)
    }
}
